package com.example.warehouse.bus.dao.persist.repository.impl;

import com.example.warehouse.bus.dao.persist.mapper.BusProviderMapper;
import com.example.warehouse.bus.dao.persist.repository.IBusProviderRepository;
import com.example.warehouse.bus.pojo.entity.BusProvider;
import com.example.warehouse.bus.pojo.vo.BusCustomerStandardVO;
import com.example.warehouse.bus.pojo.vo.BusProviderStandardVO;
import com.example.warehouse.common.pojo.vo.PageData;
import com.example.warehouse.common.util.PageInfoToPageDataConverter;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Linger
 * @date 2023-07-07 8:57
 * @desciption: 处理供应商数据的实体类
 */
@Slf4j
@Repository
public class BusProviderRepositoryImpl implements IBusProviderRepository {

    @Autowired
    private BusProviderMapper busProviderMapper;

    public BusProviderRepositoryImpl() {
        log.info("创建控制器对象: BusProviderRepositoryImpl");
    }


    /**
     * 增
     * @param busProvider 供应商数据
     * @return 受影响的行数
     */
    @Override
    public int insert(BusProvider busProvider) {
        log.debug("开始执行【新增供应商】的数据访问，参数：{}", busProvider);
        return busProviderMapper.insert(busProvider);
    }

    @Override
    public int countByProviderName(String providerName) {
        log.debug("开始执行【统计供应商数量】的数据访问，参数：{}", providerName);
        return busProviderMapper.countByProviderName(providerName);
    }

    @Override
    public int countByProviderPhone(String phone) {
        log.debug("开始执行【统计供应商手机号码数量】的数据访问，参数：{}", phone);
        return busProviderMapper.countByProviderPhone(phone);
    }

    @Override
    public int countByProviderEmail(String email) {
        log.debug("开始执行【统计供应商电子邮箱数量】的数据访问，参数：{}", email);
        return busProviderMapper.countByProviderEmail(email);
    }

    @Override
    public int deleteByProviderId(Long id) {
        log.debug("开始执行【根据ID删除供应商】的数据访问，参数：{}", id);
        return busProviderMapper.deleteById(id);
    }

    @Override
    public int update(BusProvider busProvider) {
        log.debug("开始执行【修改客户】的数据访问，参数：{}", busProvider);
        return busProviderMapper.updateById(busProvider);
    }

    @Override
    public BusProviderStandardVO getStandardByProviderId(Long id) {
        log.debug("通过id查询所有供应商信息,参数：{}",id);
        return busProviderMapper.getStandardByProviderId(id);
    }

    @Override
    public PageData<BusProviderStandardVO> queryByKeyWord(Integer pageNum, Integer pageSize,String providerName, String connectionPerson, String phone) {
        log.debug("模糊查询,{},{},{}",providerName, connectionPerson, phone);
        PageHelper.startPage(pageNum, pageSize);
        List<BusProviderStandardVO> list = busProviderMapper.queryByKeyWord(providerName, connectionPerson, phone);
        PageInfo<BusProviderStandardVO> pageInfo = new PageInfo<>(list);
        PageData<BusProviderStandardVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }

    @Override
    public PageData<BusProvider> list(Integer pageNum, Integer pageSize) {
        log.debug("开始执行【查询供应商列表】的数据访问，页码：{}，每页记录数：{}", pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<BusProvider> list = busProviderMapper.list();
        PageInfo<BusProvider> pageInfo = new PageInfo<>(list);
        PageData<BusProvider> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }

    @Override
    public PageData<BusProvider> listAsc(Integer pageNum, Integer pageSize) {
        log.debug("开始执行【查询供应商列表】的数据访问，页码：{}，每页记录数：{}", pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<BusProvider> list = busProviderMapper.listAsc();
        PageInfo<BusProvider> pageInfo = new PageInfo<>(list);
        PageData<BusProvider> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }

    @Override
    public PageData<BusProvider> listDesc(Integer pageNum, Integer pageSize) {
        log.debug("开始执行【查询供应商列表】的数据访问，页码：{}，每页记录数：{}", pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<BusProvider> list = busProviderMapper.listDesc();
        PageInfo<BusProvider> pageInfo = new PageInfo<>(list);
        PageData<BusProvider> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }

    @Override
    public int updateByProviderId(BusProvider user) {
        log.debug("开始执行【更新供应商】的数据访问，参数：{}", user);
        return busProviderMapper.updateById(user);
    }
}
